<script setup lang="ts">
import { reactive, onMounted, ref, nextTick, onUnmounted, computed } from "vue";
import { useRouter } from "vue-router";
import newUser from "@/assets/svg/new_users.svg?component";
import * as echarts from "echarts";
import { ElMessage } from "element-plus";
import type { ECharts } from "echarts";
import { getAllStores } from "@/api/costumes";
import { getBookingTimeSlots } from "@/api/bookings";

const router = useRouter();

const welcomeData = reactive({
  userName: "管理员",
  greetText: getGreetText(),
  quickLinks: [
    { title: "商品管理", icon: "ShoppingBag", path: "/goods" },
    { title: "订单管理", icon: "List", path: "/orders" },
    { title: "用户管理", icon: "User", path: "/users" },
    { title: "数据统计", icon: "Chart", path: "/dashboard" }
  ],
  statistics: [
    {
      title: "今日订单",
      value: 126,
      unit: "单",
      trend: "+12%",
      color: "#409EFF"
    },
    {
      title: "商品总数",
      value: 1580,
      unit: "件",
      trend: "+5%",
      color: "#67C23A"
    },
    {
      title: "活跃用户",
      value: 2451,
      unit: "人",
      trend: "+18%",
      color: "#E6A23C"
    },
    {
      title: "总销售额",
      value: 89654,
      unit: "元",
      trend: "+25%",
      color: "#F56C6C"
    }
  ]
});

function getGreetText() {
  const hour = new Date().getHours();
  if (hour < 6) return "夜深了";
  if (hour < 11) return "早上好";
  if (hour < 14) return "中午好";
  if (hour < 18) return "下午好";
  return "晚上好";
}

// 店铺和预约时间相关状态
const storeList = ref<any[]>([]);
const selectedStoreId = ref("1");
const dateList = ref<string[]>([]);
const selectedDate = ref("");
const timeSlots = ref<any>({});
const loading = ref(false);

// 生成未来7天的日期
const generateDateList = () => {
  const dates = [];
  const today = new Date();

  for (let i = 0; i < 7; i++) {
    const date = new Date();
    date.setDate(today.getDate() + i);
    const dateStr = date.toISOString().split("T")[0]; // 格式化为 YYYY-MM-DD
    const dayNames = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    const dayName = dayNames[date.getDay()];
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const formattedDate = `${month < 10 ? "0" + month : month}-${
      day < 10 ? "0" + day : day
    }`;

    dates.push({
      date: dateStr,
      dayName,
      formattedDate
    });
  }

  dateList.value = dates;
  selectedDate.value = dates[0].date;
};

// 获取所有店铺
const fetchStores = async () => {
  try {
    const res = await getAllStores();
    if (res.code === 200 && res.data) {
      storeList.value = res.data;
      if (storeList.value.length > 0) {
        selectedStoreId.value = storeList.value[0].id;
      }
    }
  } catch (error) {
    console.error("获取店铺列表失败:", error);
    ElMessage.error("获取店铺列表失败");
  }
};

// 获取预约时间段
const fetchTimeSlots = async () => {
  if (!selectedStoreId.value || !selectedDate.value) return;

  loading.value = true;
  try {
    const res = await getBookingTimeSlots(
      selectedStoreId.value,
      selectedDate.value
    );
    if (res.code === 200 && res.data) {
      timeSlots.value = res.data;
    }
  } catch (error) {
    console.error("获取预约时间段失败:", error);
    ElMessage.error("获取预约时间段失败");
  } finally {
    loading.value = false;
  }
};

// 当店铺或日期改变时重新获取时间段
const handleStoreChange = () => {
  fetchTimeSlots();
};

const handleDateChange = () => {
  fetchTimeSlots();
};

// 获取时间段状态类名
const getTimeSlotClass = (status: any) => {
  // 检查是否有number属性
  if (typeof status === "object" && status.number !== undefined) {
    const num = parseInt(status.number);
    if (num < 3) return "available";
    if (num >= 3 && num <= 5) return "busy";
    return "booked";
  }

  // 向下兼容原来的字符串判断
  if (status === "可预约") return "available";
  if (status === "较忙") return "busy";
  return "booked";
};

onMounted(() => {
  // initOrderChart();
  initUserChart();
  initCharts();
  window.addEventListener("resize", () => {
    // orderChart?.resize();
    userChart?.resize();
  });

  // 初始化日期和获取店铺
  generateDateList();
  fetchStores();
  fetchTimeSlots();
});

onUnmounted(() => {
  window.removeEventListener("resize", () => {
    // orderChart?.resize();
    userChart?.resize();
  });
  // orderChart?.dispose();
  userChart?.dispose();
});

// 注释掉原来的initOrderChart函数
// function initOrderChart() {
//   nextTick(() => {
//     const chart = echarts.init(document.getElementById("orderChart"));
//     if (chart) {
//       chart.setOption({
//         title: { text: "近7日订单趋势", left: "center" },
//         tooltip: { trigger: "axis" },
//         xAxis: {
//           type: "category",
//           data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
//         },
//         yAxis: { type: "value" },
//         series: [
//           {
//             data: [150, 230, 224, 218, 135, 147, 260],
//             type: "line",
//             smooth: true
//           }
//         ]
//       });
//     }
//   });
// }

function initUserChart() {
  nextTick(() => {
    const chart = echarts.init(document.getElementById("userChart"));
    if (chart) {
      const userOption = {
        title: {
          // text: "用户来源",
          left: "center",
          textStyle: {
            fontWeight: "bold",
            fontSize: 16
          }
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
          orient: "horizontal",
          top: "10px",
          left: "center",
          itemWidth: 10,
          itemHeight: 10,
          textStyle: {
            fontSize: 12
          }
        },
        color: ["#FF6A88", "#FFB199", "#36BFFA", "#9254DE", "#52C41A"],
        series: [
          {
            name: "用户来源",
            type: "pie",
            radius: ["30%", "55%"],
            center: ["50%", "55%"],
            avoidLabelOverlap: true,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
              shadowBlur: 10,
              shadowColor: "rgba(0, 0, 0, 0.2)"
            },
            label: {
              show: true,
              position: "outside",
              formatter: "{b}: {d}%",
              fontSize: 11,
              color: "#666",
              lineHeight: 12,
              padding: [0, -10],
              distanceToLabelLine: -5
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 12,
                fontWeight: "bold"
              },
              itemStyle: {
                shadowBlur: 20,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            },
            labelLine: {
              show: true,
              length: 10,
              length2: 5,
              smooth: false
            },
            data: [
              { value: 1048, name: "抖音" },
              { value: 735, name: "小红书" },
              { value: 580, name: "美团" },
              { value: 484, name: "大众点评" },
              { value: 300, name: "自主进店" }
            ],
            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay: function (idx) {
              return Math.random() * 200;
            }
          }
        ]
      };
      chart.setOption(userOption);
    }
  });
}

// 待办事项
const todoList = ref([
  {
    type: "订单",
    content: "新订单待确认 - 汉服写真套餐",
    time: "10分钟前",
    status: "待处理"
  },
  {
    type: "客服",
    content: "用户咨询待回复",
    time: "30分钟前",
    status: "紧急"
  },
  {
    type: "系统",
    content: "系统更新提醒",
    time: "2小时前",
    status: "普通"
  }
]);

// 初始化图表
let orderChart: ECharts | null = null;
let userChart: ECharts | null = null;

const quickStats = reactive([
  {
    title: "今日订单",
    value: 126,
    trend: "+12%",
    icon: "ShoppingCart"
  },
  {
    title: "商品总数",
    value: 1580,
    trend: "+5%",
    icon: "Goods"
  },
  {
    title: "活跃用户",
    value: 2451,
    trend: "+18%",
    icon: "User"
  },
  {
    title: "总销售额",
    value: "89,654",
    trend: "+25%",
    icon: "Money"
  }
]);

const initCharts = () => {
  nextTick(() => {
    // const orderChartDom = document.getElementById("orderChart");
    const userChartDom = document.getElementById("userChart");

    // if (orderChartDom) {
    //   orderChart = echarts.init(orderChartDom);
    //   const orderOption = {
    //     title: {
    //       text: "订单趋势",
    //       left: "center"
    //     },
    //     tooltip: {
    //       trigger: "axis"
    //     },
    //     xAxis: {
    //       type: "category",
    //       data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
    //       axisLine: {
    //         lineStyle: {
    //           color: "#ddd"
    //         }
    //       }
    //     },
    //     yAxis: {
    //       type: "value",
    //       axisLine: {
    //         show: false
    //       },
    //       splitLine: {
    //         lineStyle: {
    //           color: "#eee"
    //         }
    //       }
    //     },
    //     series: [
    //       {
    //         name: "订单数",
    //         type: "line",
    //         smooth: true,
    //         data: [120, 132, 101, 134, 90, 230, 210],
    //         itemStyle: {
    //           color: "#409EFF"
    //         },
    //         areaStyle: {
    //           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    //             {
    //               offset: 0,
    //               color: "rgba(64,158,255,0.3)"
    //             },
    //             {
    //               offset: 1,
    //               color: "rgba(64,158,255,0.1)"
    //             }
    //           ])
    //         }
    //       }
    //     ]
    //   };
    //   orderChart.setOption(orderOption);
    // }

    if (userChartDom) {
      userChart = echarts.init(userChartDom);
      const userOption = {
        // title: {
        //   text: "用户来源",
        //   left: "center",
        //   textStyle: {
        //     fontWeight: "bold",
        //     fontSize: 16
        //   }
        // },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
          orient: "horizontal",
          top: "10px",
          left: "center",
          itemWidth: 10,
          itemHeight: 10,
          textStyle: {
            fontSize: 12
          }
        },
        color: ["#FF6A88", "#FFB199", "#36BFFA", "#9254DE", "#52C41A"],
        series: [
          {
            name: "用户来源",
            type: "pie",
            radius: ["30%", "55%"],
            center: ["50%", "55%"],
            avoidLabelOverlap: true,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
              shadowBlur: 10,
              shadowColor: "rgba(0, 0, 0, 0.2)"
            },
            label: {
              show: true,
              position: "outside",
              formatter: "{b}: {d}%",
              fontSize: 11,
              color: "#666",
              lineHeight: 12,
              padding: [0, -10],
              distanceToLabelLine: -5
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 12,
                fontWeight: "bold"
              },
              itemStyle: {
                shadowBlur: 20,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            },
            labelLine: {
              show: true,
              length: 10,
              length2: 5,
              smooth: false
            },
            data: [
              { value: 1048, name: "抖音" },
              { value: 735, name: "小红书" },
              { value: 580, name: "美团" },
              { value: 484, name: "大众点评" },
              { value: 300, name: "自主进店" }
            ],
            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay: function (idx) {
              return Math.random() * 200;
            }
          }
        ]
      };
      userChart.setOption(userOption);
    }
  });
};

// 处理待办事项
const handleTodo = (item: any) => {
  ElMessage.success(`正在处理: ${item.content}`);
};

// 添加日期和天气文本
const currentDate = ref(
  new Date().toLocaleDateString("zh-CN", {
    year: "numeric",
    month: "long",
    day: "numeric",
    weekday: "long"
  })
);
const weatherText = ref("晴朗");

// 添加图表时间范围
const chartTimeRange = ref("week");

// 添加图标映射函数
const getStatIcon = (title: string) => {
  const iconMap: Record<string, string> = {
    今日订单: "ShoppingCart",
    商品总数: "Goods",
    活跃用户: "User",
    总销售额: "Money"
  };
  return iconMap[title] || "DataLine";
};

// 添加标签类型判断函数
const getTagType = (status: string) => {
  switch (status) {
    case "紧急":
      return "danger";
    case "待处理":
      return "warning";
    default:
      return "info";
  }
};

defineOptions({
  name: "Welcome"
});
</script>

<template>
  <div class="welcome-container animate-in">
    <!-- 顶部欢迎区域 -->
    <div class="welcome-header">
      <div class="header-content">
        <div class="greeting-section">
          <div class="greeting-text">
            <h1>{{ welcomeData.greetText }}，{{ welcomeData.userName }}</h1>
            <p class="subtitle">今天是{{ currentDate }}，祝您工作愉快！</p>
          </div>
        </div>
        <div class="decoration">
          <img
            src="@/assets/welcome/49868ef65580eb06079c1c96eb544be.png"
            alt="welcome-bg"
          />
        </div>
      </div>
    </div>

    <!-- 数据概览卡片 -->
    <div class="data-overview">
      <el-row :gutter="20">
        <el-col
          v-for="(card, index) in welcomeData.statistics"
          :key="card.title"
          :span="6"
        >
          <div
            class="data-card"
            :style="{
              '--delay': `${index * 0.1}s`,
              '--accent-color': card.color
            }"
          >
            <div class="card-content">
              <div class="icon-wrapper">
                <el-icon><component :is="getStatIcon(card.title)" /></el-icon>
              </div>
              <div class="data-info">
                <div class="main-value">
                  <span class="counter">{{ card.value }}</span
                  ><span class="unit">{{ card.unit }}</span>
                </div>
                <div class="data-title">{{ card.title }}</div>
              </div>
            </div>
            <div class="trend-info">
              <span class="trend-value">{{ card.trend }}</span>
              <span class="trend-text">较上周</span>
            </div>
            <div class="card-bg-decoration" />
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 图表区域 -->
    <div class="chart-section">
      <el-row :gutter="20">
        <el-col :span="16">
          <div class="chart-card booking-card">
            <div class="chart-header">
              <h3>预约时间段查询</h3>
              <div class="store-selector">
                <el-select
                  v-model="selectedStoreId"
                  placeholder="选择店铺"
                  @change="handleStoreChange"
                >
                  <el-option
                    v-for="store in storeList"
                    :key="store.id"
                    :label="store.name"
                    :value="store.id"
                  />
                </el-select>
              </div>
            </div>

            <div v-loading="loading" class="booking-container">
              <!-- 日期选择 -->
              <div class="date-selector">
                <div
                  v-for="(dateItem, index) in dateList"
                  :key="index"
                  class="date-item"
                  :class="{ active: selectedDate === dateItem.date }"
                  @click="
                    selectedDate = dateItem.date;
                    handleDateChange();
                  "
                >
                  <div class="day-name">{{ dateItem.dayName }}</div>
                  <div class="date-number">{{ dateItem.formattedDate }}</div>
                </div>
              </div>

              <!-- 时间段图例 -->
              <div class="time-slot-legend">
                <div class="legend-item">
                  <div class="color-block available" />
                  <span>可预约 (人数＜3)</span>
                </div>
                <div class="legend-item">
                  <div class="color-block busy" />
                  <span>较忙 (3-5人)</span>
                </div>
                <div class="legend-item">
                  <div class="color-block booked" />
                  <span>拥挤 (＞5人)</span>
                </div>
              </div>

              <!-- 时间段列表 -->
              <div class="time-slots-grid">
                <div
                  v-for="(slot, time, slotIndex) in timeSlots"
                  :key="time"
                  class="time-slot-item"
                  :style="{ '--delay': `${slotIndex * 0.05}s` }"
                >
                  <div class="time">{{ slot.time }}</div>
                  <div :class="['status', getTimeSlotClass(slot)]">
                    {{
                      typeof slot === "object"
                        ? slot.number < 3
                          ? "可预约"
                          : slot.number >= 3 && slot.number <= 5
                            ? "较忙"
                            : "拥挤"
                        : slot
                    }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="chart-card user-chart-card">
            <div class="chart-header">
              <h3>用户来源分析</h3>
              <div class="chart-actions">
                <el-radio-group v-model="chartTimeRange" size="small">
                  <el-radio-button label="week">本周</el-radio-button>
                  <el-radio-button label="month">本月</el-radio-button>
                </el-radio-group>
              </div>
            </div>
            <div id="userChart" class="chart-container" />
            <div class="chart-summary">
              <div class="summary-item">
                <div class="summary-label">总用户量</div>
                <div class="summary-value">3,147</div>
              </div>
              <div class="summary-item">
                <div class="summary-label">增长率</div>
                <div class="summary-value">+18.2%</div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 快捷操作区域 -->
    <div class="quick-actions-section">
      <div class="section-title">
        <h3>快捷操作</h3>
      </div>
      <div class="quick-actions-grid">
        <div
          v-for="(link, index) in welcomeData.quickLinks"
          :key="link.title"
          class="quick-action-card"
          :style="{ '--delay': `${index * 0.1}s` }"
          @click="router.push(link.path)"
        >
          <div class="action-icon">
            <el-icon><component :is="link.icon" /></el-icon>
          </div>
          <div class="action-title">{{ link.title }}</div>
        </div>
      </div>
    </div>

    <!-- 待办事项 -->
    <div v-if="todoList.length > 0" class="todo-section">
      <div class="todo-header">
        <h3>待办事项</h3>
        <el-button type="primary" text>查看全部</el-button>
      </div>
      <div class="todo-list">
        <div
          v-for="(item, index) in todoList"
          :key="index"
          class="todo-item"
          :style="{ '--delay': `${index * 0.1}s` }"
          @click="handleTodo(item)"
        >
          <div class="todo-content">
            <el-tag
              :type="getTagType(item.status)"
              effect="plain"
              size="small"
              >{{ item.type }}</el-tag
            >
            <span class="todo-text">{{ item.content }}</span>
          </div>
          <div class="todo-meta">
            <span class="time">{{ item.time }}</span>
            <el-icon class="arrow"><ArrowRight /></el-icon>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes float {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0px);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes countUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.welcome-container {
  padding: 24px;
  background: #f8f9fc;
  min-height: calc(100vh - 84px);

  &.animate-in {
    animation: fadeInUp 0.6s ease-out;
  }

  .welcome-header {
    background: linear-gradient(135deg, #8c5e2a 0%, #b88d56 100%);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
    color: white;
    box-shadow: 0 8px 24px rgba(140, 94, 42, 0.2);
    position: relative;
    overflow: hidden;

    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3z' fill='%23ffffff' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E");
      opacity: 0.3;
    }

    .header-content {
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: relative;
      z-index: 1;

      .greeting-section {
        .greeting-text {
          h1 {
            font-size: 36px;
            font-weight: 600;
            margin-bottom: 12px;
            letter-spacing: 1px;
            animation: fadeInUp 0.6s ease-out 0.2s both;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
          }

          .subtitle {
            font-size: 16px;
            opacity: 0.9;
            margin-bottom: 24px;
            animation: fadeInUp 0.6s ease-out 0.3s both;
          }
        }
      }

      .decoration {
        width: 300px;
        height: 200px;
        animation: float 6s ease-in-out infinite;

        .welcome-svg {
          width: 100%;
          height: 100%;
          filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
        }
      }
    }
  }

  .data-overview {
    margin-bottom: 24px;

    .data-card {
      --accent-color: #409eff;
      background: white;
      border-radius: 16px;
      padding: 24px;
      height: 140px;
      transition: all 0.3s ease;
      position: relative;
      overflow: hidden;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
      animation: fadeInUp 0.6s ease-out both;
      animation-delay: var(--delay);
      border-top: 4px solid var(--accent-color);

      &:hover {
        transform: translateY(-6px);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);

        .card-bg-decoration {
          opacity: 0.2;
          transform: rotate(15deg) scale(1.2);
        }

        .icon-wrapper {
          transform: scale(1.1);
        }
      }

      .card-content {
        display: flex;
        align-items: flex-start;
        gap: 16px;
        margin-bottom: 16px;
        position: relative;
        z-index: 1;

        .icon-wrapper {
          width: 56px;
          height: 56px;
          border-radius: 16px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 28px;
          background: var(--accent-color);
          color: white;
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
          transition: all 0.3s ease;
        }

        .data-info {
          .main-value {
            font-size: 32px;
            font-weight: 700;
            color: #1f2329;
            line-height: 1.2;

            .counter {
              display: inline-block;
              animation: countUp 0.8s ease-out forwards;
              animation-delay: calc(var(--delay) + 0.3s);
            }

            .unit {
              font-size: 14px;
              margin-left: 4px;
              color: #86909c;
              font-weight: 500;
            }
          }

          .data-title {
            font-size: 14px;
            color: #4e5969;
            margin-top: 4px;
            font-weight: 500;
          }
        }
      }

      .trend-info {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 13px;
        position: relative;
        z-index: 1;

        .trend-value {
          color: #67c23a;
          font-weight: 600;
        }

        .trend-text {
          color: #86909c;
        }
      }

      .card-bg-decoration {
        position: absolute;
        top: -20%;
        right: -20%;
        width: 180px;
        height: 180px;
        border-radius: 50%;
        background: var(--accent-color);
        opacity: 0.05;
        transition: all 0.5s ease;
        transform: rotate(0) scale(1);
        z-index: 0;
      }
    }
  }

  .chart-section {
    margin-bottom: 24px;

    .chart-card {
      background: white;
      border-radius: 16px;
      padding: 24px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
      animation: scaleIn 0.6s ease-out both;
      height: 460px;
      transition: all 0.3s ease;
      position: relative;
      overflow: hidden;

      &:hover {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
      }

      &.booking-card {
        animation-delay: 0.8s;

        &::before {
          content: "";
          position: absolute;
          top: 0;
          right: 0;
          width: 150px;
          height: 150px;
          background: linear-gradient(
            135deg,
            rgba(140, 94, 42, 0.05) 0%,
            rgba(184, 141, 86, 0.05) 100%
          );
          border-radius: 0 0 0 100%;
        }
      }

      &.user-chart-card {
        animation-delay: 1s;

        &::before {
          content: "";
          position: absolute;
          bottom: 0;
          left: 0;
          width: 150px;
          height: 150px;
          background: linear-gradient(
            135deg,
            rgba(140, 94, 42, 0.05) 0%,
            rgba(184, 141, 86, 0.05) 100%
          );
          border-radius: 0 100% 0 0;
        }
      }

      .chart-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 24px;
        position: relative;
        z-index: 1;

        h3 {
          font-size: 18px;
          font-weight: 600;
          color: #1f2329;
          margin: 0;
          position: relative;
          padding-left: 16px;

          &::before {
            content: "";
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 18px;
            background: linear-gradient(to bottom, #8c5e2a, #b88d56);
            border-radius: 2px;
          }
        }

        .store-selector {
          min-width: 200px;
        }
      }

      .chart-container {
        height: 320px;
        position: relative;
        z-index: 1;
      }

      .chart-summary {
        display: flex;
        justify-content: space-around;
        margin-top: 16px;
        padding-top: 16px;
        border-top: 1px dashed #e4e7ed;
        position: relative;
        z-index: 1;

        .summary-item {
          text-align: center;

          .summary-label {
            font-size: 12px;
            color: #86909c;
            margin-bottom: 4px;
          }

          .summary-value {
            font-size: 20px;
            font-weight: 600;
            color: #1f2329;
          }
        }
      }
    }
  }

  .quick-actions-section {
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease-out 1.2s both;

    .section-title {
      margin-bottom: 16px;

      h3 {
        font-size: 18px;
        font-weight: 600;
        color: #1f2329;
        margin: 0;
        position: relative;
        padding-left: 16px;

        &::before {
          content: "";
          position: absolute;
          left: 0;
          top: 50%;
          transform: translateY(-50%);
          width: 4px;
          height: 18px;
          background: linear-gradient(to bottom, #8c5e2a, #b88d56);
          border-radius: 2px;
        }
      }
    }

    .quick-actions-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 20px;

      .quick-action-card {
        background: white;
        border-radius: 16px;
        padding: 24px;
        text-align: center;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
        animation: fadeInUp 0.6s ease-out both;
        animation-delay: calc(1.2s + var(--delay));

        &:hover {
          transform: translateY(-6px);
          box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);

          .action-icon {
            background: linear-gradient(135deg, #8c5e2a 0%, #b88d56 100%);
            color: white;
            transform: scale(1.1);
          }
        }

        .action-icon {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          background: rgba(184, 141, 86, 0.1);
          color: #8c5e2a;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 24px;
          margin: 0 auto 16px;
          transition: all 0.3s ease;
        }

        .action-title {
          font-size: 16px;
          font-weight: 500;
          color: #1f2329;
        }
      }
    }
  }

  .todo-section {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    animation: slideInRight 0.6s ease-out 1.4s both;

    .todo-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;

      h3 {
        font-size: 18px;
        font-weight: 600;
        color: #1f2329;
        margin: 0;
        position: relative;
        padding-left: 16px;

        &::before {
          content: "";
          position: absolute;
          left: 0;
          top: 50%;
          transform: translateY(-50%);
          width: 4px;
          height: 18px;
          background: linear-gradient(to bottom, #8c5e2a, #b88d56);
          border-radius: 2px;
        }
      }
    }

    .todo-list {
      .todo-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.3s ease;
        animation: fadeInUp 0.6s ease-out both;
        animation-delay: calc(1.5s + var(--delay));
        margin-bottom: 10px;
        border: 1px solid transparent;

        &:hover {
          background: #f8f9fc;
          border-color: #e4e7ed;

          .arrow {
            transform: translateX(4px);
          }
        }

        .todo-content {
          display: flex;
          align-items: center;
          gap: 12px;

          .todo-text {
            font-size: 14px;
            color: #4e5969;
          }
        }

        .todo-meta {
          display: flex;
          align-items: center;
          gap: 16px;

          .time {
            font-size: 13px;
            color: #86909c;
          }

          .arrow {
            color: #86909c;
            transition: transform 0.3s ease;
          }
        }
      }
    }
  }
}

.booking-container {
  padding: 16px 0;

  .date-selector {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;

    .date-item {
      border: 1px solid #e4e7ed;
      border-radius: 12px;
      padding: 12px;
      text-align: center;
      cursor: pointer;
      transition: all 0.3s ease;
      min-width: 80px;
      background: white;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);

      &:hover {
        border-color: #b88d56;
        box-shadow: 0 4px 12px rgba(184, 141, 86, 0.1);
      }

      &.active {
        border-color: #b88d56;
        background: linear-gradient(
          135deg,
          rgba(184, 141, 86, 0.1) 0%,
          rgba(140, 94, 42, 0.05) 100%
        );
        color: #8c5e2a;
        box-shadow: 0 4px 12px rgba(184, 141, 86, 0.15);
        transform: translateY(-2px);
      }

      .day-name {
        font-size: 14px;
        margin-bottom: 4px;
        font-weight: 500;
      }

      .date-number {
        font-size: 16px;
        font-weight: 600;
      }
    }
  }

  .time-slot-legend {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-bottom: 16px;

    .legend-item {
      display: flex;
      align-items: center;
      gap: 8px;

      .color-block {
        width: 16px;
        height: 16px;
        border-radius: 4px;

        &.available {
          background-color: #67c23a;
        }

        &.busy {
          background-color: #e6a23c;
        }

        &.booked {
          background-color: #f56c6c;
        }
      }
    }
  }

  .time-slots-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    height: 184px;
    overflow: hidden;
    overflow-y: auto;
    padding-right: 8px;

    /* 滚动条样式 */
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: #f1f1f1;
      border-radius: 10px;
    }

    &::-webkit-scrollbar-thumb {
      background: #b88d56;
      border-radius: 10px;
    }

    .time-slot-item {
      height: 90px;
      border-radius: 12px;
      padding: 16px;
      text-align: center;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
      transition: all 0.3s ease;
      animation: fadeInUp 0.4s ease-out both;
      animation-delay: calc(1s + var(--delay));
      border: 1px solid #e4e7ed;
      background: white;

      &:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        transform: translateY(-2px);
      }

      .time {
        font-size: 14px;
        margin-bottom: 10px;
        font-weight: 500;
        color: #1f2329;
      }

      .status {
        padding: 6px 10px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 500;
        display: inline-block;

        &.available {
          background-color: rgba(103, 194, 58, 0.1);
          color: #67c23a;
        }

        &.busy {
          background-color: rgba(230, 162, 60, 0.1);
          color: #e6a23c;
        }

        &.booked {
          background-color: rgba(245, 108, 108, 0.1);
          color: #f56c6c;
        }
      }
    }
  }
}

* {
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform, opacity;
}
</style>
